package ajax17;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.mysql.jdbc.Driver;

/**
 * Servlet implementation class RegServlet
 */
public class RegServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegServlet() {
    	super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		String userid;
		String nickname;
		String pw1;
		String pw2;
		String email;
				
		if (req.getParameter("userid") != null){
			userid = req.getParameter("userid");
			nickname = req.getParameter("userid");
			pw1 = req.getParameter("pw1");
			pw2 = req.getParameter("pw2");
			email = req.getParameter("email");
			
			member m = new member(userid, nickname, pw1, pw2, email);
			HttpSession session = req.getSession();
			session.setAttribute("m", m);
			
			if (m.validate()){
				// 註冊成功 Forword
				//req.getRequestDispatcher("success.jsp")
				//.forward(req, resp);
				// Redirect
				resp.sendRedirect("success.jsp");
			}else{
				//
				resp.sendRedirect("reg2.jsp");
			}
			
		}
	}
	/**
	 * @see HttpServlet#doPost(HttpServletRequest req, HttpServletResponse resp)
	 */
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}

}
